package org.budo.execute.limit.exception;

import java.lang.reflect.Method;

import org.budo.execute.limit.annotation.ExecuteLimit;
import org.springframework.core.annotation.AnnotationUtils;

/**
 * @author limingwei
 */
public class ExecuteLimitException extends RuntimeException {
    private static final long serialVersionUID = 4785465935752280667L;

    private Method method;

    private ExecuteLimit annotation;

    public ExecuteLimitException() {}

    public ExecuteLimitException(Method method) {
        this.method = method;
        this.annotation = AnnotationUtils.findAnnotation(method, ExecuteLimit.class);
    }

    public ExecuteLimitException(Method method, ExecuteLimit annotation) {
        this.method = method;
        this.annotation = annotation;
    }

    @Override
    public String getMessage() {
        String message = super.getMessage();
        return (null == message ? "" : message + ", ") + "method=" + this.getMethod() + ", annotation=" + this.getAnnotation();
    }

    public ExecuteLimit getAnnotation() {
        return this.annotation;
    }

    public void setAnnotation(ExecuteLimit annotation) {
        this.annotation = annotation;
    }

    public void setMethod(Method method) {
        this.method = method;
    }

    public Method getMethod() {
        return this.method;
    }
}